#include "StdAfx.h"
#include "GRASP.h"
#include "ConstructionPhase.h"
#include <limits>


using namespace std;

void GRASP::ejecutar() 
{
	srand(2);
	//seguir de aca! ver como manejar el tema de la soluciones, si es la misma clase grafo o que
	Red * solActual;
	Red * bestSol = NULL;
	Red * solLocal;

	ConstructionPhase * constructor = new ConstructionPhase(grafo, listSize);
//	LocalSearchMinUtility * localSearchMinUtility = new LocalSearchMinUtility();

	double costoMinimo = numeric_limits<double>::max();
	for (int i=0; i<maxIter; i++) {

		solActual = constructor->ejecutar();

		/*
		solLocal = new Red(solActual);
		do {
			delete solActual;
			solActual = solLocal;
			double costActual = solActual->getCosto();
			solLocal = localSearchMinUtility->ejecutar(grafo, solActual);
			double bestLocal = solLocal->getCosto();

		} while (bestLocal < costActual);
		*/
		
		if (solActual->getCosto() < costoMinimo) {
			costoMinimo = solActual->getCosto();
			if (sol != NULL) {
				delete sol;
			}
			sol = solActual;
		}
	
	}

	delete constructor;
	//delete localSearchMinUtility;
}

void GRASP::printSolucion()
{

}

Red * GRASP::getSolucion()
{
	return sol;
}

GRASP::~GRASP(void)
{
	delete grafo;
}
